<?php

namespace app\home\controller;

use app\home\model\config;
use srcker\Captcha;

class mainControl extends control
{
    function index()
    {
        $config = new config();
        return $this->ok($config->findAll());
    }

    function captcha()
    {
        $config = [
            // 验证码字符集合
            'codeSet' => '2345678abcdefhijkmnpqrstuvwxyzABCDEFGHJKLMNPQRTUVWXY',
            // 使用中文验证码
            'useZh' => true,
            // 中文验证码字符串
            'zhSet' => '专业瘦身网站汇富康达减肥',
            // 使用背景图片
            'useImgBg' => false,
            // 验证码字体大小(px)
            'fontSize' => 25,
            // 是否画混淆曲线
            'useCurve' => true,
            // 是否添加杂点
            'useNoise' => true,
            // 验证码图片高度
            'imageH' => 0,
            // 验证码图片宽度
            'imageW' => 0,
            // 验证码位数
            'length' => 4,
            // 验证码字体，不设置随机获取
            'fontttf' => '',
            // 背景颜色
            'bg' => [243, 251, 254],
        ];
        $captcha = new Captcha($config);
        $captchaObj = $captcha->entry();
        $this->exit("<title>动态验证码</title><meta name=\"viewport\" content=\"width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1\"><img src='{$captchaObj['base64']}' />");
    }

    function mysql()
    {
        $config = new config();
        dump($config->query("SELECT SUBSTRING_INDEX(HOST,':',1) AS ip , COUNT(*) as count FROM information_schema.processlist GROUP BY ip;"));
        $this->exit();
    }
}